// store/index.ts
import { createStore } from "vuex";
import { RootState } from "./types";
import createPersistedState from "vuex-persistedstate";
import userModule from "./modules/user";
import playModule from "./modules/play";

const store = createStore<RootState>({
    modules: {
        user: userModule,
        play: playModule,
    },
    getters: {
        currentSong: (state) => state.play.currentPlayingSong,
        currentUsername: (state) => state.user.username,
        currentName: (state) => state.user.name,
        authFields: (state) => ({
            username: state.user.username,
            salt: state.user.subsonicSalt,
            sToken: state.user.subsonicToken,
        }),
    },
    plugins: [
        // 使用localStorage做本地化持久存储
        createPersistedState({
            storage: window.localStorage,
        }),
    ],
});

export default store;
